package com.atguigu.inner.anymous;

public class TestStudent {
    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("张三",85);
        students[1] = new Student("李四",90);
        students[2] = new Student("王五",75);

        System.out.println("数组的元素：");
        for (Student student : students) {
            System.out.println(student);
        }

        //找最大值
//        MyArrays.findMax(students, new MyComparator());//因为接口不能直接创建对象
        MyComparator my = new MyComparator() {
            @Override
            public int compare(Object o1, Object o2) {
                Student s1 = (Student) o1;
                Student s2 = (Student) o2;
                /*if(s1.getScore() > s2.getScore()){
                    return 1;
                }else if(s1.getScore() < s2.getScore()){
                    return -1;
                }else{
                    return 0;
                }*/

                return s1.getScore() - s2.getScore();
            }
        };
        Object max = MyArrays.findMax(students, my);
        System.out.println("最高分的同学：" + max);
    }
}
